{template 'common/header'}
{if $rid!=''}
		{template 'nav'}
	{/if}

<div class="main table-responsive">
	<div class="alert alert-warning" role="alert">
		注意：授权域名不能有重复。
	</div>
	<form method="post" class="form-horizontal" id="form1">
		<div class="panel panel-default">
			<div class="panel-body table-responsive">
				<table class="table table-hover">
					<thead class="navbar-inner">
					<tr>
						<th style="width:50px;">删？</th>
						<th style="width:60%;">授权域名</th>
						<th style="width:100px;">授权ip</th>
					</tr>
					</thead>
					<tbody id="list">
					{loop $list $item}
					<tr>
						<td style="vertical-align:middle;"><input type="checkbox" name="delete[]" value="{$item['id']}" /></td>
						<td><input type="text" name="oauthurl[{$item['id']}]" class="form-control" style="width:100%" value="{$item['oauthurl']}" /></td>
						<td><input type="text" name="visitorsip[{$item['id']}]" class="form-control" style="width:100px" value="{$item['visitorsip']}" /></td>
					</tr>
					{/loop}
					</tbody>
					<tbody style="border-top:0;">
					<tr>
						<td></td>
						<td colspan="2">
							<a href="javascript:;" onclick="addItem()"><i class="icon-plus-sign-alt"></i> 添加</a>
						</td>
					</tr>
					</tbody>
				</table>
			</div>
		</div>
		<div>
			<input name="token" type="hidden" value="{$_W['token']}" />
			<input type="submit" class="btn btn-primary col-lg-1" name="submit" value="提交" />
		</div>
		<div>
		
		</div>
	</form>
	
</div>
<script type="text/javascript">
<!--
	function addItem() {
		var html = '' +
				'<tr>' +
					'<td></td>' +
					'<td><input type="text" name="oauthurl-new[]" class="form-control oauthurl-new" style="width:250px" value="" /></td>' +
					'<td><input type="text" name="visitorsip-new[]" class="form-control visitorsip-new" style="width:250px;display:inline" value="" />' +
					'<a href="javascript:;"  style="padding-left:20px;"onclick="deleteItem(this);"><i class=""></i>删除</a>' +
					'</td>' +
				'</tr>';
		$('#list').append(html);
	}
	function deleteItem(o) {
		$(o).parent().parent().remove();
	}

require(['jquery', 'util'], function($, u){
	$("#form1").submit(function(){
		var colarr=new Array();
		var col;
		var titlearr=new Array();
		var tit;
		var bool=true;
			
		$(":text[name^=oauthurl]").each(function(index){
			oauthurl=$(this).val().trim();
			if(oauthurl==""){
				u.message('授权域名不能为空.', '', 'error');
				bool = false;
			}
			if(oauthurl !=""){
				for(tit in titlearr){
					if(titlearr[tit]==oauthurl){
						u.message('授权域名重复，请设置不同的授权域名.', '', 'error');
						bool = false;
					}		
				}
				titlearr[index+1]=oauthurl;
			}	
		})
		if(!bool) return false;
	});
});
//-->
</script>
{template 'common/footer'}